package com.smart.car.points.controller;

import com.alibaba.fastjson.JSONObject;
import com.smart.car.common.res.bean.ResponseResult;
import com.smart.car.common.res.exception.BusinessException;
import com.smart.car.points.entity.PointsSign;
import com.smart.car.points.service.PointsSignService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

/**
 * TODO 用户签到打卡控制
 * @author zoutao.blog.csdn.net
 * @date 2021-03-03
 */

@Slf4j
@RestController
@RequestMapping("sign")
public class PointsSignController {


    @Autowired
    private PointsSignService signService;

    /**
     * TODO 签到服务
     * {"cnt":50,"ctype":0,"memberId":"133123456789"}
     * @param json
     */
    @RequestMapping(value = "/add", method = RequestMethod.POST)
    public ResponseResult<Integer> add(String json) throws BusinessException {
		/* 测试gateway的retry机制是否正常运行
		 * if (StringUtils.isEmpty("")) {
			throw new BusinessException("测试网关重试机制");
		}*/
        ResponseResult<Integer> result = new ResponseResult<>();
        int rtn = signService.sign(json);
        result.setData(rtn);
        return result;
    }

    public static void main(String[] args) {
        PointsSign sign = new PointsSign();
        sign.setMemberId("133123456789");
        sign.setCnt(50);
        sign.setCtype(0);
        log.info(JSONObject.toJSONString(sign));
    }
}
